package com.gec.anan.customer.controller;

import com.gec.anan.common.login.AnanLogin;
import com.gec.anan.common.result.Result;
import com.gec.anan.common.util.AuthContextHolder;
import com.gec.anan.customer.service.CustomerService;
import com.gec.anan.model.form.customer.UpdateWxPhoneForm;
import com.gec.anan.model.vo.customer.CustomerLoginVo;
import com.gec.anan.model.vo.driver.DriverLoginVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "客户API接口管理")
@RestController
@RequestMapping("/customer")
@SuppressWarnings({"unchecked", "rawtypes"})
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 小程序授权登录
     * @param code
     * @return
     */
    @Operation(summary = "根据code获取用户id")
    @GetMapping("/login/{code}")
    public Result<String> getCustomerId(@PathVariable String code) {
        log.info("小程序客户登录{}",code);
        return Result.ok(customerService.login(code));
    }

    /**
     * 根据id获取用户信息
     */
    @Operation(summary = "根据id获取用户信息")
    @GetMapping("/getCustomerLoginInfo")
    @AnanLogin
    public Result<CustomerLoginVo> getCustomerInfo(){
        //从thredLocal获取id
        Long customerId = AuthContextHolder.getUserId();
        return Result.ok(customerService.getCustomerInfo(customerId));
    }
    /**
     * 更新手机号
     */
    @Operation(summary = "更新客户微信手机号码")
    @PostMapping("/updateWxPhone")
    @AnanLogin
    public Result<Boolean> updateWxPhoneNumber(@RequestBody UpdateWxPhoneForm updateWxPhoneForm) {
        Long userId = AuthContextHolder.getUserId();
        updateWxPhoneForm.setCustomerId(userId);
        log.info("用户id{}",userId);
        return Result.ok(customerService.updateWxPhoneNumber(updateWxPhoneForm));
    }
}

